home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / Bookmark.subproj / eTBookmarkBinder.m < prev    next >
Encoding:
Text File  |  1994-12-07  |  2.7 KB  |  108 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    eTBookmarkBinder.m 
  3. //    SUMMARY:    Appwide rendezvous point for bookmark management
  4. //    SUPERCLASS:    Object
  5. //    INTERFACE:    None
  6. //    PROTOCOLS:    None
  7. //    AUTHOR:        Rohit Khare
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. ///////////////////////////////////////////////////////////////////////////////
  10. //  IMPLEMENTATION COMMENTS
  11. //        We maintain a table of document-wide anchor tables; registration and
  12. //    unregistration ensure consistency. Aside from lookup and query functions,
  13. //    the Binder will offer to fill a matrix as used in a browser. There is only
  14. //    one of these in the runtime space (this being an application whose runtime
  15. //  is distributed over at most one virtual processor :)
  16. ///////////////////////////////////////////////////////////////////////////////
  17. //    HISTORY
  18. //    06/15/94:    Added dirty bit management. RK & TRZ
  19. //    05/08/94:    Created. First actual implementation.
  20. ///////////////////////////////////////////////////////////////////////////////
  21.  
  22. #import "eTBookmarkBinder.h"
  23.  
  24. @implementation eTBookmarkBinder
  25. //    id    docTable;
  26. //    id    anchorTable;
  27.  
  28. + new
  29. {
  30.     static eTBookmarkBinder *binder = nil;
  31.     
  32.     if (!binder) {
  33.         binder = [[eTBookmarkBinder alloc] init];
  34.     }
  35.     return binder;    
  36. }
  37.  
  38. - init
  39. {
  40.     [super init];
  41.     dirtyBit = YES;
  42.     docTable = [[HashTable alloc] initKeyDesc:"i" valueDesc:"@"];
  43.     anchorTable = [[HashTable alloc] initKeyDesc:"i" valueDesc:"@"];
  44.     return self;
  45. }
  46.  
  47. - free
  48. {
  49. //    [docTable freeObjects];
  50. //    [docTable free];
  51. //    [anchorTable free];
  52. //    return [super free];
  53.     return self;
  54. }
  55.  
  56. - registerBM:theBookmark ID:(long)anchorID inDoc:(long)docID
  57. {
  58.     id aTab;
  59.     
  60.     aTab = [docTable valueForKey:docID];
  61.     if (!aTab)
  62.         [docTable insertKey:docID value:(aTab = [[HashTable alloc] initKeyDesc:"i" valueDesc:"@"])]; 
  63.     [aTab insertKey:anchorID value:theBookmark];
  64.     [anchorTable insertKey:anchorID value:theBookmark];
  65.     dirtyBit = YES;
  66.     return self;
  67. }
  68.  
  69. - unregisterBM:theBookmark ID:(long)anchorID inDoc:(long)docID
  70. {
  71.     id aTab;
  72.     
  73.     aTab = [docTable valueForKey:docID];
  74.     if (aTab) [aTab removeKey:anchorID];
  75.     [anchorTable removeKey:anchorID];
  76.     //Q: did we just invalidate the browser? are we in trouble?
  77.     dirtyBit = YES;
  78.     return self;
  79. }
  80.  
  81.  
  82. - getBookmarks:theStorage inDoc:(long)docID
  83. {    
  84.     NXHashState state;
  85.     long key;
  86.     id value;
  87.     id aTab;
  88.     
  89.     //iterate over states and populate the list
  90.     aTab = [docTable valueForKey:docID];
  91.     state = [aTab initState];
  92.     while ([aTab nextState:&state key:(void **) &key value: (void**) &value])
  93.         [theStorage addElement:&value];
  94.     return self;
  95. }
  96.  
  97. - bookmarkForID:(long)anchorID
  98. {
  99.     return ((id) [anchorTable valueForKey:anchorID]);
  100. }
  101.  
  102. - (BOOL) isDirty
  103. {
  104.     if (dirtyBit) 
  105.         {dirtyBit = NO; return YES;}
  106.     else return NO;
  107. }
  108. @end